package com.auxgroup.hr.front.site.co.modPerson;

import javax.annotation.Resource;
import javax.validation.Valid;

import com.auxgroup.hr.front.site.inteceptor.SessionGain;
import com.auxgroup.hr.front.site.vo.modperson.ModTactPerQueForm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.auxgroup.hr.front.commons.vo.BaseResponseVO;
import com.auxgroup.hr.front.commons.vo.UserDTO;
import com.auxgroup.hr.front.dao.domain.PsCModPhotoTactPerPrimary;
import com.auxgroup.hr.front.dao.domain.PsCModTactPer;
import com.auxgroup.hr.front.dozer.IObjectMapper;
import com.auxgroup.hr.front.service.modperson.ModTactPerService;
import com.auxgroup.hr.front.site.co.BaseCO;
import com.auxgroup.hr.front.site.inteceptor.SessionGain;
import com.auxgroup.hr.front.site.vo.modperson.ModTactPerQueForm;

/**
 * 紧急联系人流程信息CO
 * @author lvliuhao
 * @version 创建时间：180526 
 */
@RestController
@RequestMapping("${auxgroup.hr.contextPath}/modTactPer")
public class ModTactPerCO extends BaseCO {

	private static final Logger logger = LoggerFactory.getLogger(ModTactPerCO.class);

	@Autowired
	public ModTactPerService modTactPerService;

	@Resource(name = "dozerMapper")
	protected IObjectMapper objectMapper;

	/**
	 * 保存紧急联系人流程信息
	 * @param hireId
	 * @return
	 */
	@PostMapping(value = "/save")
	public BaseResponseVO save(@Valid ModTactPerQueForm queForm, @SessionGain("user") UserDTO user, BindingResult binding) {
		logger.info("saveModTactPer param= {}", queForm);
		//表单校验
		super.assertValidation(binding);
		PsCModPhotoTactPerPrimary primary = new PsCModPhotoTactPerPrimary();
		primary.setcTransactionNbr(queForm.getcTransactionNbr());
		primary.setEmplid(queForm.getEmplid());
		PsCModTactPer modTactPer = modTactPerService.getModTactPer(primary);
		if(modTactPer!=null){
			objectMapper.map(queForm, modTactPer,"notCopyNull_modTactPer");
		}else{
			modTactPer = objectMapper.map(queForm, PsCModTactPer.class);
		}
		modTactPer = modTactPerService.save(modTactPer,user);
		if(modTactPer.getEmplid()!=null){
			return buildRespone(true);
		}
		return buildRespone(false);
	}
	
	/**
	 * 获取紧急联系人流程信息
	 * @param hireId
	 * @return
	 */
	@GetMapping(value = "/getOne")
	public BaseResponseVO getOne(PsCModPhotoTactPerPrimary modTactPerPrimary) {
		logger.info("getModTactPer param= {}", modTactPerPrimary);
		PsCModTactPer modTactPer = modTactPerService.getModTactPer(modTactPerPrimary);
		return buildRespone(modTactPer);
	}
	
}
